package cn.xscrum.vtsp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.vtsp.domain.VtspAcademy;
import cn.xscrum.vtsp.service.IVtspAcademyService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 学院信息Controller
 * 
 * @author Zhangh
 * @date 2021-10-01
 */
@Controller
@RequestMapping("/vtsp/academy")
public class VtspAcademyController extends BaseController
{
    private String prefix = "vtsp/academy";

    @Autowired
    private IVtspAcademyService vtspAcademyService;

    @RequiresPermissions("vtsp:academy:view")
    @GetMapping()
    public String academy()
    {
        return prefix + "/academy";
    }

    /**
	 * 查询学院信息列表
     */
    @RequiresPermissions("vtsp:academy:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VtspAcademy vtspAcademy)
    {
        startPage();
        List<VtspAcademy> list = vtspAcademyService.selectVtspAcademyList(vtspAcademy);
        return getDataTable(list);
    }

    /**
	 * 导出学院信息列表
     */
    @RequiresPermissions("vtsp:academy:export")
    @Log(title = "学院信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VtspAcademy vtspAcademy)
    {
        List<VtspAcademy> list = vtspAcademyService.selectVtspAcademyList(vtspAcademy);
        ExcelUtil<VtspAcademy> util = new ExcelUtil<VtspAcademy>(VtspAcademy.class);
        return util.exportExcel(list, "academy");
    }

    /**
	 * 新增学院信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存学院信息
     */
    @RequiresPermissions("vtsp:academy:add")
    @Log(title = "学院信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    //新建操作
    public AjaxResult addSave(VtspAcademy vtspAcademy)
    {

        System.out.println("请求了此方法");
        System.out.println("前端传来的参数 --------------" + vtspAcademy);
        return toAjax(vtspAcademyService.insertVtspAcademy(vtspAcademy));
    }

    /**
	 * 修改学院信息
     */
    @GetMapping("/edit/{academyId}")
    //修改操作
    public String edit(@PathVariable("academyId") Long academyId, ModelMap mmap)
    {
        VtspAcademy vtspAcademy = vtspAcademyService.selectVtspAcademyById(academyId);
        mmap.put("vtspAcademy", vtspAcademy);
        return prefix + "/edit";
    }

    /**
	 * 修改保存学院信息
     */
    @RequiresPermissions("vtsp:academy:edit")
    @Log(title = "学院信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VtspAcademy vtspAcademy)
    {
        System.out.println("请求了此方法");
        System.out.println("前端传来的参数 --------------" + vtspAcademy);
        return toAjax(vtspAcademyService.updateVtspAcademy(vtspAcademy));
    }

    /**
	 * 删除学院信息
     */
    @RequiresPermissions("vtsp:academy:remove")
    @Log(title = "学院信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        System.out.println("请求了此方法");
        System.out.println("前端传来的参数 --------------" + ids);
        return toAjax(vtspAcademyService.deleteVtspAcademyByIds(ids));
    }
}
